/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import Entities.Artist;
import Entities.Director;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

/**
 *
 * @author sebastian
 */
public class DirectorController {
              EntityManagerFactory emf = Persistence.createEntityManagerFactory("GRLU");
     
  public List<Director> getDirectorbyName(String directorName){
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery<Director> query = (TypedQuery<Director>) em.createNamedQuery("Director.findByName", Director.class);
        query.setParameter("name", directorName);
        List<Director> resultsDirectors = query.getResultList();        
        return resultsDirectors;
    }
  
  public Director getSingleDirector(String nameDirector){
   
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery query = (TypedQuery) em.createNamedQuery("Director.findByName", Director.class);
        query.setParameter("name", nameDirector);
        Director results = (Director)query.getSingleResult();
        
        return results;                
    }
}
